package com.zzyl.common.client;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.auth.Auth;
import com.baidubce.qianfan.model.chat.ChatResponse;
import com.zzyl.common.properties.QianFanProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class AiQianFanClient {

    @Autowired
    private QianFanProperties qianFanProperties;


    public String qianfanInvoker(String prompt) {
        log.info("开始调用千帆模型解析");
        Qianfan qianfan = new Qianfan(Auth.TYPE_OAUTH, qianFanProperties.getAccessKey(), qianFanProperties.getSecretKey());
        ChatResponse chatResponse = qianfan.chatCompletion()
                .model(qianFanProperties.getQianfanModel())
                .addMessage("user", prompt)
                .temperature(0.7)
                .maxOutputTokens(2000)
                .responseFormat("json_object")
                .execute();
        String result = chatResponse.getResult();
        log.info("大模型解析结果：{}", result);
        return result;
    }

}
